package com.newcoder.community.serverce;

import com.newcoder.community.dao.DisCussPostMapper;
import com.newcoder.community.pojo.DiscussPost;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class DiscussPostServiceImpl implements DiscussPostService {
    @Autowired
   private DisCussPostMapper disCussPostMapper;
    @Override
    public List<DiscussPost> queryAll() {
        List<DiscussPost> discussPosts = disCussPostMapper.queryAll();
        return discussPosts;
    }

    @Override
    public List<DiscussPost> selectDiscussPosts(int userId, int offset, int limit) {
        List<DiscussPost> discussPosts = disCussPostMapper.selectDiscussPosts(userId,offset,limit);
        return discussPosts;
    }

    @Override
    public int selectDiscussPostRows(int userId) {
        int i = disCussPostMapper.selectDiscussPostRows(userId);
        return i;
    }

    @Override
    public int addDiscussPost(DiscussPost discussPost) {
        if(discussPost==null){
            try {
                throw  new IllegalAccessException("参数不能不能为空");
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }

        }
        return disCussPostMapper.insertDiscussPost(discussPost);
    }

    @Override
    public DiscussPost queryById(int id) {
        return disCussPostMapper.queryById(id);
    }

    @Override
    public int updateCommentCount(int id, int commentCount) {
        return disCussPostMapper.updateCommentCount(id,commentCount);
    }
}
